*------------------------------------------------------------------------------*
		*** BAR PLOT WITH NUMBER OF ELECTIONS BY CALENDAR MONTH ***
*------------------------------------------------------------------------------*

use "${tempdata}kreise_complete_all.dta", clear

*------------------------------------------------------------------------------*

*Generate election month
gen election_month = month(election_date)

preserve

	*Restrict sample to estimation sample
	keep if  samplePM10_allcontrols == 1

	*Keep only one observation for each electio in each State
	by Land election_date, sort: gen a = 1 if _n == 1
	keep if a == 1
	drop if election_type == "BW" & Land != "Bayern"  // This is to have only 5 national elections

	*Contract to leave frequencies
	contract election_month, freq(count)
	
	*Add months with 0 elections: July, November, December
	set obs `=_N+1'
	replace election_month = 7 if count == .
	replace count = 0 if count == .
	set obs `=_N+1'
	replace election_month = 11 if count == .
	replace count = 0 if count == .
	set obs `=_N+1'
	replace election_month = 12 if count == .
	replace count = 0 if count == .
	
	*Label months
	label define label_mon 1 "Jan" 2 "Feb" 3 "Mar" 4  "Apr" 5 "May" 6 "Jun" 7 "Jul" 8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec"
	label values  election_month label_mon

	*Bar plot
	graph bar count, over(election_month) label ytitle("Number of elections") graphregion(color(white)) bgcolor(white)
	graph export "${outputs}figure_S4.png", replace

restore

*------------------------------------------------------------------------------*

clear

exit
